//
//  PurchaseHelper.swift
//  IncomeAndExpense
//
//  Created by HOA on 2021/8/21.
//
import Foundation
import Purchases

public struct PurchasesHelper {
    
    static var entitlementID = ""
    
    /// configure
    ///
    /// - parameter apiKey:
    /// - parameter entitlementID:
    /// - parameter logLevel: .debug
    static public func configure(apiKey: String, entitlementID: String, logLevel: Purchases.LogLevel = .debug) {
        self.entitlementID = entitlementID
        Purchases.logLevel = logLevel
        Purchases.configure(withAPIKey: apiKey)
        /* Set the delegate to our shared instance of PurchasesDelegateHandler */
        Purchases.shared.delegate = PurchasesDelegateHandler.shared

        /* Fetch the available offerings */
        Purchases.shared.offerings { (offerings, error) in
            UserViewModel.shared.objectWillChange.send()
            UserViewModel.shared.offerings = offerings
        }
    }
}
